package view.impl;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import bean.UserBean;
import cqut.edu.cn.temp_20160410.R;

import presenter.impl.UserLoginPresenter;
import view.IUserLoginView;

/**
 * 用户登录
 */
public class LoginActivity extends AppCompatActivity implements OnClickListener,
		IUserLoginView {

	EditText mEtUname;// 用户名
	EditText mEtPasswd;// 密码
	Button mBtnLogin;// 登录
	TextView mTvLoginPro;// 无法登录
	TextView mTvRegister;// 注册
	private UserLoginPresenter mUserLoginPresenter = new UserLoginPresenter(this);

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		addListener();
	}

	public void initView() {
		mEtUname = (EditText) findViewById(R.id.etUname);
		mEtPasswd = (EditText) findViewById(R.id.etPasswd);
		mBtnLogin = (Button) findViewById(R.id.btnLogin);
		mTvLoginPro = (TextView) findViewById(R.id.tvLoginPro);
		mTvRegister = (TextView) findViewById(R.id.tvRegister);

		mTvLoginPro.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);// 设置下划线
		mTvRegister.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);// 设置下划线

	}

	public void addListener() {
		mBtnLogin.setOnClickListener(this);
		mTvLoginPro.setOnClickListener(this);
		mTvRegister.setOnClickListener(this);
	}


	@Override
	public void onClick(View view) {
		Intent intent;
		int id = view.getId();
		switch (id) {
		case R.id.btnLogin:
			mUserLoginPresenter.login();
			break;
		case R.id.tvLoginPro:
			intent = new Intent(LoginActivity.this, RegisterActivity.class);
			startActivity(intent);
			break;
		case R.id.tvRegister:
			intent = new Intent(LoginActivity.this, RegisterActivity.class);
			startActivity(intent);
			break;
		default:
			break;
		}
	}

	@Override
	public String getUsername() {
		return mEtUname.getText().toString();
	}

	@Override
	public String getPassword() {
		return mEtPasswd.getText().toString();
	}

	@Override
	public String getSex() {
		return null;
	}

	@Override
	public String getBirthDay() {
		return null;
	}

	@Override
	public String getSignature() {
		return null;
	}

	@Override
	public void showLoginError(String msg) {
		Toast.makeText(LoginActivity.this, msg, Toast.LENGTH_SHORT).show();
	}

}
